<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <crudOperation :permission="permission">
      </crudOperation>
      <div v-if="!crud.props.searchToggle">
        <!--        无搜索-->
      </div>
    </div>
    <!--表单组件-->
    <el-dialog :before-close="crud.cancelCU" :close-on-click-modal="false" :title="crud.status.title"
               :visible.sync="crud.status.cu > 0" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" size="small">
        <el-form-item label="编码">
          <el-input v-model="form.code" style="width: 370px;"/>
        </el-form-item>
        <el-form-item label="名称" prop="name" >
          <el-input v-model="form.name" style="width: 370px;"/>
        </el-form-item>
        <el-form-item label="税率(%)" prop="rate" >
          <el-input-number :precision="2" :step="0.1" v-model="form.rate" :min="0" :max="100" style="width: 370px;">
          </el-input-number>
        </el-form-item>
        <el-form-item label="排序">
          <el-input-number v-model="form.seq" :min="1" label="排序" style="width: 370px;"></el-input-number>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="form.status" class="edit-input" placeholder="请选择" style="width: 370px;">
            <el-option
                v-for="(item,index) in dict.common_status"
                :key="index"
                v-if="item.seq>0"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" style="width: 370px;"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
      </div>
    </el-dialog>
    <div class="body-container">

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->

      <el-table ref="table"  border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" label="序号" type="index" width="60"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" label="编码" prop="code"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" label="名称" prop="name" show-overflow-tooltip/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('rate')" label="税率" prop="rate"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('seq')" label="排序" prop="seq"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" label="状态" prop="status">-->
<!--          <template slot-scope="scope">-->
<!--            {{ dict.label.common_status[scope.row.status] }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" label="备注" prop="remark"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','basTax:edit','basTax:del']" align="center" label="操作" width="150px">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--                :data="scope.row"-->
<!--                :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudBasTax from '@/api/erp/basTax'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";

// crud交由presenter持有
const defaultCrud = CRUD({title: '税种', url: 'api/basTax', sort: 'code,asc', crudMethod: {...crudBasTax}})
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  rate: null,
  seq: null,
  status: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'BasTax',
  components: {pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['common_status','t_bas_tax_type'],
  data() {
    return {
      permission: {
        add: ['admin', 'basTax:add'],
        edit: ['admin', 'basTax:edit'],
        del: ['admin', 'basTax:del'],
        enable: ['admin', 'basTax:enable'],
        disable: ['admin', 'basTax:disable'],
        pass: ['admin', 'basTax:pass'],
        reject: ['admin', 'basTax:reject'],
        invalid: ['admin', 'basTax:invalid'],
        recover: ['admin', 'basTax:recover'],
        upload: ['admin', 'basTax:upload'],
        download: ['admin', 'basTax:download'],
        copy: ['admin', 'basTax:copy'],
        notice: ['admin', 'basTax:notice'],
        isReturn: ['admin', 'basTax:isReturn']
      },
      rules: {
        name: [
          {required: true, message: '名称不能为空', trigger: 'blur'}
        ],
        rate: [
          {required: true, message: '税率不能为空', trigger: 'blur'},
        ]
      }
    }
  },
  watch: {},
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    //修改应用状态
    // enableOrDisable(type) {
    //   let ids = []
    //   let _datas = this.crud.selections;
    //   console.log(_datas);
    //   _datas.forEach(o => {
    //     ids.push(o.id)
    //   })
    //   enableOrDisable({ids:ids,type:type}).then(res => {
    //
    //   })
    // }

  }
}
</script>

<style lang="scss" scoped>
::v-deep {

}
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}


</style>
